package com.yang.design.create.singletonPattern;

/**
 * 饿汉式-懒加载
 * volatile + synchronized
 * volatile:防止指令重排
 *
 */
public class Singleton_04 {
    private volatile static Singleton_04 instance = null;
    private Singleton_04(){}

    public static Singleton_04 getInstance() {
        if (instance == null){
            synchronized (Singleton_04.class){
                if (instance == null){
                    instance = new Singleton_04();
                }
            }
        }

        return instance;
    }
}
